package com.wdj.creation.singleton.lazySingleton;

import com.wdj.creation.singleton.staticfactory.Singleton;

/**
 * @ClassName LazySingleton
 * @Description
 * @Author wdj
 * @Date 2020/8/22 9:58
 * @Version 1.0
 **/
public class LazySingleton {
    private static LazySingleton str = null;

    private LazySingleton(){}
    // 相对于静态工厂，只是加了一个锁。
    synchronized public  static LazySingleton getInstance(){
        if(str == null){
            str = new LazySingleton();
        }
        return str;
    }
    public static void main(String[] args) {
        LazySingleton singleton1 = LazySingleton.getInstance();
        LazySingleton singleton2 = LazySingleton.getInstance();
        System.out.println(singleton1 == singleton2);
        System.out.println(singleton1.equals(singleton2));

    }
}
